package com.work.keep.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.work.keep.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/20.
 */
public class DemoAdapter extends RecyclerView.Adapter<DemoAdapter.ViewHolder> {
    private List<String> datas1;
    private List<String> datas2;
    private Context context;
    private View headView;
    private View footView;
    private int headViewSize = 0;
    private int footViewSize = 0;
    private boolean isAddFoot=false;
    private boolean isAddHead=false;
    public DemoAdapter(Context context) {
        this.context = context;
        datas1 = new ArrayList<>();
        datas2 = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            datas1.add(i + "");
        }
        for (int i = 100; i < 150; i++) {
            datas2.add(i + "");
        }
    }


    public void loadMore() {
        datas1.addAll(datas2);
        notifyDataSetChanged();
    }

    public void refresh() {
        datas1.add(0, "onRefresh");
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(context).inflate(R.layout.demoitemlayout, parent, false);
        ViewHolder holder = new ViewHolder(v);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tv.setText(datas1.get(position));
    }

    @Override
    public int getItemCount() {
        return datas1.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tv;

        public ViewHolder(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.demoTV);
        }
    }
}
